#!/usr/bin/python
# -*- coding:utf-8 -*-
# @FileName : python_test9_15.py
# Author    : myh

# 练习 9.15：彩票分析　可以使用一个循环来理解中前述彩票大奖有多
# 难。为此，创建一个名为 my_ticket 的列表或元组，再编写一个循
# 环，不断地随机选择数或字母，直到中大奖为止。请打印一条消息，
# 报告执行多少次循环才中了大奖。(优化)

from random import choice,choices


hm = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 'A', 'B', 'C', 'D', 'E']


zj_hm = choices(hm, k=4)

print(f'出只要彩票上是这 4个数或字母就中大奖：{zj_hm}')

zj_flag = False
zi_num = 0
while not zj_flag:
    zi_num = zi_num+1
    random_hm = choices(hm, k=4)

    print()
    print(f"第{zi_num}次抽奖号码：{random_hm}")

    copy_zj_hm = zj_hm[:]
    for rh1 in random_hm:
        if rh1 in zj_hm:
            copy_zj_hm.remove(rh1)
        else:
            break
    if not copy_zj_hm:
        zj_flag = True
        print("中奖了")



